#ifndef MAPWIDGET_H
#define MAPWIDGET_H
#include <QVector>
#include <QObject>
#include <QWidget>
#include<QMouseEvent>
#include<QPaintEvent>
#include<QMap>
#include<QQueue>
#include<QSet>
class Mapwidget : public QWidget
{
    Q_OBJECT
public:
    explicit Mapwidget(QWidget *parent = nullptr);
    void mousePressEvent(QMouseEvent *ev);
    void paintEvent(QPaintEvent*);
    QPoint location;
    QPoint finall;  
    int locationok=0;
    int finallok=0;
    QVector<QPoint> gridPoints;
    int identity;
    QMap<long long,QPoint> carfree;
    QMap<long long,QPoint> carbuzy;
    QMap<long long,QPoint> marchant;
    QMap<long long,QPoint> orderstart;
    QMap<long long,QPoint> orderend;
    QMap<long long,int> weight;
    QSet<long long> order;
    QMap<long long,int> carweight;
    QQueue<QPoint> road;
    long long noworder=-1;
    void hanleupdate();
signals:
    void changepos();
    void updateemit();
    void chlocation(QPoint p);
    void chfinall(QPoint p);
    void chlocationok(int value);
    void chfinallok(int value);
    void chcarfreerm(long long i);
    void chcarfreein(long long i,QPoint q);
    void chcarbuzyrm(long long i);
    void chcarbuzyin(long long i,QPoint q);
    void chweight(long long i,int w);
    void chorderrm(long long i);
    void chorderin(long long i,int w);
    void chorderstartrm(long long i);
    void chorderstartin(long long i,QPoint p);
    void chorderendrm(long long i);
    void chorderendin(long long i,QPoint p);
    void chcarweight(long long i,int w);
    void chroadin(QPoint q);
    void chroadclear();
    void chnoworder(long long i);
    void chmarchantin(long long id,QPoint p);
    void chmarchantrm(long long id);
    void chorderi(long long i);
    void chorderr(long long i);
public slots:
    // Mapwidget 内部数据改变时发出的信号 (我们之前定义的)
    void locationChanged(const QPoint& newLocation);
    void locationOkChanged(int value);
    void finallLocationChanged(const QPoint& pos); // 对应 m_finall 变化
    void finallLocationOkChanged(bool ok); // 对应 m_finallok 变化

    void carFreeAddedOrUpdated(long long id, const QPoint& pos); // 之前是 int, 现在是 long long
    void carFreeRemoved(long long id);

    void carBuzyAddedOrUpdated(long long id, const QPoint& pos);
    void carBuzyRemoved(long long id);

    void carWeightChanged(long long id, int weight); // 车辆重量变化

    void orderWeightChanged(long long orderId, int weight); // 订单重量变化 (如果有)
    void orderRemoved(long long orderId); // 订单被移除 (起点，终点，重量可能一起移除)

    void roadPathSegmentAdded(const QPoint& point); // 每次添加一个点
    void roadPathCleared(); // 整个路径清空
    void changemarchantin(long long id,QPoint p);
    void changemarchantrm(long long id);
    void nowOrderChanged(long long orderId);
    void changeorderstartrm(long long i);
    void changeorderstartin(long long i,QPoint p);
    void changeorderendrm(long long i);
    void changeorderendin(long long i,QPoint p);
    void changeorderi(long long i);
    void changeorderr(long long i);
};

#endif // MAPWIDGET_H
